package RPS;


public class RockPaperScissors {
	public Result play(RPSEnum p1, RPSEnum p2){
		switch(p1){
			case ROCK:
				switch (p2) {
					case SCISSORS:
						return Result.WIN;
					case ROCK:
						return Result.TIE;
					default:
						return Result.LOST;
				}
			case SCISSORS:
				switch (p2) {
					case PAPER:
						return Result.WIN;
					case SCISSORS:
						return Result.TIE;
					default:
						return Result.LOST;
				}
			case PAPER:
				switch (p2) {
					case ROCK:
						return Result.WIN;
					case PAPER:
						return Result.TIE;
					default:
						return Result.LOST;
				}
			default :return Result.LOST;
		}
		
	}
	
	public Result play(Player p1, Player p2){
		
		RPSEnum mov1;
		RPSEnum mov2;
		Result r;
		
		for(int i=0;i<10;i++){
			mov1=p1.getNextMoves();
			mov2=p2.getNextMoves();
			
			r=play(mov1, mov2);
			
			switch(r)
			{
				case WIN: p1.setScore(p1.getScore()+1);break;
				case TIE: p1.setScore(p1.getScore()+1);p2.setScore(p2.getScore()+1);break;
				case LOST: p2.setScore(p2.getScore()+1);break;
			}
			
		}
		
		if(p1.getScore()>5)
			r=Result.WIN;
		else if(p1.getScore()==5)
			r=Result.TIE;
		else r=Result.LOST;
		
		return r;
		
	}
}
